package com.tedu.jsd2407_ivos_fzj.user.controller;

import com.tedu.jsd2407_ivos_fzj.base.response.JsonResult;
import com.tedu.jsd2407_ivos_fzj.user.pojo.dto.UserLoginParam;
import com.tedu.jsd2407_ivos_fzj.user.pojo.dto.UserQuery;
import com.tedu.jsd2407_ivos_fzj.user.pojo.dto.UserSaveParam;
import com.tedu.jsd2407_ivos_fzj.user.pojo.vo.UserVO;
import com.tedu.jsd2407_ivos_fzj.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;
    @PostMapping("login")
    public JsonResult login(UserLoginParam userLoginParam){
        log.debug("用户登录：参数={}",userLoginParam);
        /*ctrl:进入接口，ctrl+alt:进入实现类，ctrl+shift：进入返回值所在类*/
        UserVO userVO = userService.login(userLoginParam);
        return JsonResult.ok(userVO);
    }
    @PostMapping("save")
    public JsonResult save(UserSaveParam userSaveParam){
        log.debug("新增/修改用户：参数={}",userSaveParam);
        userService.saveUser(userSaveParam);
        return JsonResult.ok();
    }
    @GetMapping("/select")
    public JsonResult select(UserQuery userQuery){
        log.debug("查询用户，参数:{}",userQuery);
        List<UserVO> userVOList = userService.selectUser(userQuery);
        log.debug("查询用户，返回数据:{}",userVOList);
        return JsonResult.ok(userVOList);
    }
    @PostMapping("/update/password/{id}")
    public JsonResult resetPassword(@PathVariable Long id){
        log.debug("重置密码，参数：{}",id);
        userService.resetPassword(id);
        return JsonResult.ok();
    }
    @PostMapping("/update/status/{id}/{status}")
    public JsonResult updateStatus(@PathVariable Long id,@PathVariable String status){
        log.debug("修改状态，参数1{}，参数2{}",id,status);
        userService.updateStatus(id,status);
        return JsonResult.ok();
    }
    @PostMapping("/delete/{id}")
    public JsonResult deleteUser(@PathVariable Long id){
        userService.deleteUser(id);
        return JsonResult.ok();
    }
    @GetMapping("/select/audit/{id}")
    public JsonResult selectAuditList(@PathVariable Long id){
        log.debug("查询审批人，参数：{}",id);
        List<UserVO> userVOList = userService.selectAuditList(id);
        return JsonResult.ok(userVOList);
    }
}
